package class202205.demo10.demo06;

import java.util.Scanner;

public class demo20220506 {
    public static void tt(int n){
        System.out.print("奇数位:");
        for (int i = 31; i >0; i-=2) {
            System.out.print(((n >> i)&1)+" ");
        }
        System.out.println();
        System.out.print("偶数位:");
        for (int i = 30; i >= 0; i-=2) {
            System.out.print(((n >> i)&1)+" ");
        }
    }
    public static void main(String[] args) {
        tt(7);
    }

    public static void kpl3(int n) {
        if ((n&(n-1))==0){
            System.out.println("这个数是2^k");
        }else {
            System.out.println("这个数不是2^k");
        }
    }

    public static void main13(String[] args) {
        kpl3(8);
    }

    public static int kpl2(int n){
        int count = 0;
        while (n!=0){
            count++;
            n = n&(n-1);
        }
        return count;
    }

    public static void main12(String[] args) {
        System.out.println(kpl2(7));
    }

    public static int kpl1(int n){
        int count = 0;
        while (n!=0){
            if ((n&1)!=0){
                count++;
            }
            n = n >>> 1;
        }
        return count;
    }

    public static void main11(String[] args) {
        System.out.println(kpl1(1));
    }


    public static int kpl(int n){
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if (((n>>i) & 1)!=0){
                count++;
            }
        }
        return count;
    }

    public static void main10(String[] args) {
        System.out.println(kpl(1));
    }

    public static void atm1(){
        for (int num = 0; num < 999_999; num++) {
            int count = 0;
            int net = num;
            while (net != 0) {
                count++;
                net /= 10;
            }
            net = num;
            int sum = 0;
            while (net != 0) {
                sum += Math.pow(net % 10, count);
                net /= 10;
            }
            if (sum == num) {
                System.out.println(sum);
            }
        }
    }

    public static void main9(String[] args) {
        atm1();
    }

    public static void atm(){
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int num = sc.nextInt();
            int count = 0;
            int net = num;
            while (net != 0) {
                count++;
                net /= 10;
            }
            net = num;
            int sum = 0;
            while (net != 0) {
                sum += Math.pow(net % 10, count);
                net /= 10;
            }
            if (sum == num) {
                System.out.println("所输入的是水仙花数：" + sum);
            } else {
                System.out.println("所输入的不是水仙花数！");
            }
        }
        sc.close();
    }

    public static void main8(String[] args) {
        atm();
    }

    public static int tim(int a,int b){
       int c = a%b;
       while (c!=0){
           a = b;
           b = c;
           c = a%b;
       }
       return b;
    }
    public static void main7(String[] args) {
        System.out.println(tim(96, 268));
    }

    public static void fun() {
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < i+1; j++) {
                System.out.print(j+"*"+i+"="+j*i+" " );
            }
            System.out.println();
        }
    }

    public static void main6(String[] args) {
        fun();
    }

    public static boolean sun(int num) {
        for (int i = 2; i < Math.sqrt(num); i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main5(String[] args) {
         if (sun(7)){
             System.out.println("是素数！");
         }else {
             System.out.println("不是素数！");
         }
    }

    public static void main4(String[] args) {
        Scanner sc = new Scanner(System.in);
        int suv = (int) (Math.random() * 100);

        /*Random random = new Random();
        int toGuess = random.nextInt(100);*/

        while (sc.hasNext()) {
            System.out.println("请输入你想输入的数字：（1-100）");
            int set = sc.nextInt();
            if (set < suv) {
                System.out.println("猜小了！");
            } else if (set > suv) {
                System.out.println("猜大了!");
            } else {
                System.out.println("猜中了！");
            }
        }
        sc.close();
    }

    public static void main3(String[] args) {
        System.out.println((int)(Math.random() * 100));
    }
    public static void main2(String[] args) {
        int sum = 0;
        for (int i = 0; i <= 100; i+=2) {
            sum +=i;
        }
        int snm = 0;
        for (int j = 1; j < 100; j+=2) {
            snm += j;
        }
        System.out.println("偶数和为+"+sum);
        System.out.println("奇数和为+"+snm);
    }
    public static void main1(String[] args) {
        int i =1;
        while ( i<101){
            if (i%15!=0){
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }
}
